package cn.picclife.mwx.app.util;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import cn.picclife.mwx.app.util.*;

@Component
public class OSSUtil {
	
	//定义OSS的Bucket名称
	@Value("${file.oss.bucket}")
	private static  String OSS_BUCKET;
	
	//定义OSS主机域名
	@Value("${file.oss.host}")
	private static  String OSS_HOST;
	
	@Value("${file.access.key}")
	private static  String OSS_USER_ACCESS_KEY;
	
	@Value("${file.secret.key}")
	private static  String OSS_USER_SECRET_KEY ;
	
	@Value("${file.oss.server}")
	private static String OSS_SERVER;
	
	
	public final static  Map<String,String> headers = new HashMap<String, String>();

	static{
		  headers.put("X-amz-acl", "public-read-write");
		  
		  //TODO 
		//  headers.put("auth", null);
		  headers.put("access_key", OSS_USER_ACCESS_KEY);
		  headers.put("secret_key", OSS_USER_SECRET_KEY);
		  
	}
	

	
	/*public static String createBucket(String bucket){
		String reqUrl = OSS_SERVER +"/%s";
	    String  jb = HttpsUtil.httpsPutRequest(String.format(reqUrl, bucket), headers, null);	    
	    return jb;
	}*/
	
	/*public static String getBucketList(){
		String reqUrl = OSS_SERVER +"/?format=json";
	    String  jb = HttpsUtil.httpsPutRequest(reqUrl, headers, null);	    
	    return jb;
	}*/
	
	 /*public static String createUploadObject(String bucket,String obj){
		String reqUrl = OSS_SERVER +"%s/%s";
	    String  jb = HttpsUtil.httpsPutRequest(String.format(reqUrl, bucket,obj), headers, null);	    
	    return jb;
	}*/
	
	 /*public static String initUploadId(String bucket,String obj){
		String reqUrl = OSS_SERVER +"%s/%s?uploads";
	    String  jb = HttpsUtil.httpsPutRequest(String.format(reqUrl, bucket,obj), headers, null);	    
	    return jb;
	}*/
	 
	 /**
	  * 
	  * @param bucket
	  * @param obj
	  * @param partNumber  //这个参数怎么获取
	  * @param uploadId
	  * @return
	  */
	/* public static String uploadChunk(String bucket,String obj,int partNumber,String uploadId){
			String reqUrl = OSS_SERVER +"%s/%s?partNumber=%d&uploadId=%s";
		    String  jb = HttpsUtil.httpsPutRequest(String.format(reqUrl, bucket,obj,partNumber,uploadId), headers, null);	    
		    return jb;
		}*/
	 
	 /*public static String dowloadObj(String bucket,String obj){
			String reqUrl = OSS_SERVER +"%s/%s";
		    String jb = null;
			try {
				jb = HttpsUtil.httpsGetRequest(String.format(reqUrl, bucket,obj), "UTF-8", headers, null, null);
			} catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		    return jb;
		}*/

	 
}
